﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BullTasDesaDal.Entities;

namespace WSBulTasDesa.UserControls
{
    public partial class ucFilter : System.Web.UI.UserControl
    {
        public Filter Filter
        {
            get
            {
                Filter filter = new Filter();
                if (!string.IsNullOrEmpty(ddlProvinces.SelectedValue))
                    filter.IdProvince = Convert.ToInt16(ddlProvinces.SelectedValue);
                if (!string.IsNullOrEmpty(ddlDepartments.SelectedValue))
                    filter.IdDepartment = Convert.ToInt32(ddlDepartments.SelectedValue);
                if (!string.IsNullOrEmpty(ddlRegions.SelectedValue))
                    filter.IdRegion = ddlRegions.SelectedValue;
                if (!string.IsNullOrEmpty(ddlZones.SelectedValue))
                    filter.IdZone = ddlZones.SelectedValue;
                if (!string.IsNullOrEmpty(txtEstablishmentName.Text.Trim()))
                    filter.EstablishmentName = txtEstablishmentName.Text;
                if (!string.IsNullOrEmpty(txtFromDate.Text.Trim()))
                    filter.FromDate = Convert.ToDateTime(txtFromDate.Text);
                if (!string.IsNullOrEmpty(txtToDate.Text.Trim()))
                    filter.ToDate = Convert.ToDateTime(txtToDate.Text).AddHours(23).AddMinutes(59).AddSeconds(59);


                return filter;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                txtFromDate.Attributes.Add("readonly", "readonly");
                txtToDate.Attributes.Add("readonly", "readonly");

            }
        }
    }
}